package com.itheim.controller;

import com.itheim.anno.Log;
import com.itheim.pojo.PageResult;
import com.itheim.pojo.Result;
import com.itheim.pojo.Student;
import com.itheim.pojo.StudentQueryParem;
import com.itheim.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/students")
public class StudentController {

    @Autowired
    private StudentService studentService;
    //条件分页查询
    @GetMapping
    public Result page(StudentQueryParem studentQueryParem){
        log.info("条件分页查询");
        PageResult<Student> pageResult=studentService.page(studentQueryParem);
        return Result.success(pageResult);
    }
    //新增学生信息
    @Log
    @PostMapping
    public Result addstudent(@RequestBody Student student){
        log.info("新增学生信息");
        studentService.addstudent(student);
        return Result.success();
    }

    //修改信息回显
    @GetMapping("/{id}")
    public Result getById(@PathVariable Integer id){
        log.info("修改信息回显");
        Student student=studentService.getById(id);
        return Result.success(student);
    }

    //修改学员
    @Log
    @PutMapping
    public Result update(@RequestBody Student student){
        log.info("修改学员");
        studentService.update(student);
        return Result.success();
    }
    //4.2 删除学员
    @Log
    @DeleteMapping("/{ids}")
    public Result delete(@PathVariable Integer[] ids){
        log.info("删除学员");
        studentService.delete(ids);
        return Result.success();
    }
    //4.6 违纪处理
    @Log
    @PutMapping("/violation/{id}/{score}")
    public Result violationHandle(@PathVariable Integer id,@PathVariable Integer score){
        log.info("违纪处理");
        studentService.violationHandle(id,score);
        return Result.success();
    }


}
